#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/12/29 14:19
    Desc  :
--------------------------------------
"""
from io import BytesIO

import xlwt
import xlrd


class ExcelClient:
    """
    excel导出
    """

    def __init__(self):
        self.excel_headers = []
        # 创建一个文件对象
        self.wb = xlwt.Workbook(encoding = 'utf-8')
        # 创建一个文件对象
        self.sheet = self.wb.add_sheet('sheet1')

        # self.file = None
        # self.rb = xlrd.open_workbook(filename = self.file)

    def export(self, data: list):

        for i in range(len(self.excel_headers)):
            self.sheet.write(0, i, self.excel_headers[i])

        data_row = 1
        for i in data:
            self.sheet.write(data_row, 0, i)
        output = BytesIO()
        self.wb.save(output)
        output.seek(0)
        return output
